<template>
  <Panel>
    <template v-slot:con>
      <!-- 查询 -->
      <el-form
        :inline="true"
        :model="searchForm"
        class="demo-form-inline"
        size="mini"
        ref="searchForm"
      >
        <el-form-item label="订单号" prop="orderNo">
          <el-input
            v-model="searchForm.orderNo"
            placeholder="订单号"
          ></el-input>
        </el-form-item>
        <el-form-item label="收货人" prop="consignee">
          <el-input
            v-model="searchForm.consignee"
            placeholder="收货人"
          ></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="searchForm.phone" placeholder="手机号"></el-input>
        </el-form-item>

        <el-form-item label="订单状态" prop="orderState">
          <el-select v-model="searchForm.orderState" placeholder="订单状态">
            <el-option label="已受理" value="已受理"></el-option>
            <el-option label="派送中" value="派送中"></el-option>
            <el-option label="已完成" value="已完成"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="下单时间" prop="date">
          <el-date-picker
            v-model="searchForm.date"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button type="" @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
      <!-- 列表 -->
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="orderNo" label="订单号" width="120">
        </el-table-column>
        <el-table-column label="下单日期" width="150">
          <template v-slot="{ row }">
            {{ row.orderTime | formatDate }}
          </template>
        </el-table-column>
        <el-table-column prop="phone" label="手机号" width="120">
        </el-table-column>
        <el-table-column prop="consignee" label="收货人姓名" width="120">
        </el-table-column>
        <el-table-column prop="deliverAddress" label="配送地址" width="300">
        </el-table-column>
        <el-table-column prop="deliveryTime" label="送达时间" width="120">
        </el-table-column>
        <el-table-column prop="remarks" label="用户备注" width="120">
        </el-table-column>
        <el-table-column prop="orderAmount" label="订单金额" width="120">
          <template v-slot="{ row }">
            {{ row.orderAmount | fromatMoney }}
          </template>
        </el-table-column>
        <el-table-column prop="orderState" label="订单状态" width="120">
        </el-table-column>

        <el-table-column fixed="right" label="操作" width="100">
          <template v-slot="{ row }">
            <el-button @click="handleClick(row)" type="text" size="small"
              >查看</el-button
            >
            <el-button
              type="text"
              size="small"
              @click="
                $router.push({
                  path: '/Order/edit',
                  query: { id: row.id },
                })
              "
              >编辑</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!--分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[2, 5, 10, 15]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </template>
  </Panel>
</template>

<script>
import { getOrderList } from "../../api/orders.js";
export default {
  data() {
    return {
      pageSize: 5,
      currentPage: 1,
      total: 0,
      searchForm: {
        orderNo: "",
        consignee: "",
        phone: "",
        orderState: "",
        date: "",
      },
      tableData: [],
    };
  },
  created() {
    this.getorderlist();
  },
  methods: {
    handleSizeChange(val) {
      this.pageSize = val;
      this.getorderlist();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getorderlist();
    },
    async getorderlist() {
      const { data, total } = await getOrderList({
        pageSize: this.pageSize,
        currentPage: this.currentPage,
        orderNo: this.searchForm.orderNo,
        consignee: this.searchForm.consignee,
        phone: this.searchForm.phone,
        orderState: this.searchForm.orderState,
        date: JSON.stringify(this.searchForm.date),
      });
      this.total = total;
      this.tableData = data;
    },

    // 查询列表
    onSubmit() {
      this.currentPage = 1;
      this.getorderlist();
    },

    // 重置信息
    resetForm() {
      this.$refs.searchForm.resetFields();
      this.searchForm.data = "";
      this.getorderlist();
    },
  },
};
</script>

<style lang="less" scoped>
.el-pagination {
  padding: 30px 20px;
}
</style>